package com.xxxx.controller;

import com.alibaba.fastjson.JSONObject;
import com.tools.FileRead;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

@Controller
@RequestMapping("/boot")
public class BootController {




    @RequestMapping("/index")
    public String index(Model model) {
        model.addAttribute("ss", "123");
        System.out.print("xxxx");
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        return "user/login";
    }

    @PostMapping("/login")
    @ResponseBody
    public String login(String usr, String pas, HttpServletRequest request) {
        JSONObject jsonObject = new JSONObject();
         try {
             if ( FileRead.map.containsKey(usr)) {
                 String s = FileRead.map.get(usr);
                 if (s.equals(pas)) {
                     jsonObject.put("info", "success");
                 } else {
                     jsonObject.put("info", "密码错误");
                 }
             } else {
                 jsonObject.put("info", "用户名不存在");
             }
         } catch (Exception e) {
             jsonObject.put("info", "exception");
            e.printStackTrace();
        }
        return jsonObject.toJSONString();
    }
}
